import tkinter as tk

top = tk.Tk()
top.resizable(False, False)

q1_option = tk.IntVar()
q1_option.set(0)
q2_option = tk.IntVar()
q2_option.set(0)
# 31,32,33,34
q3_option = tk.IntVar() 
q3_option.set(0)
# 41,42,43,44
q4_option = tk.IntVar()
q4_option.set(0)

def AddSingleChoiceQuestion(top, question, option_str, option_var):
    question_frame = tk.Frame(top)
    question_frame.pack(side=tk.TOP, fill=tk.X)
    question = tk.Label(question_frame, text=question, anchor=tk.W)
    question.pack(side=tk.TOP, fill=tk.X)
    option_frame = tk.Frame(question_frame)
    option_frame.pack(side=tk.TOP, fill=tk.X)
    
    options = option_str.split(':')

    for i in range(len(options)):
        opt = tk.Radiobutton(option_frame, text=options[i], variable=option_var, value=i + 1)
        opt.pack(side=tk.LEFT) 

def AddMultipleChoiceQuestion(top, question, option_str, option_var):
    question_frame = tk.Frame(top)
    question_frame.pack(side=tk.TOP, fill=tk.X)
    question = tk.Label(question_frame, text=question, anchor=tk.W, width = len(question))
    question.pack(side=tk.TOP, fill=tk.X)
    option_frame = tk.Frame(question_frame)
    option_frame.pack(side=tk.TOP, fill=tk.X)

    options = option_str.split('|')
    
    for item in options:
        opt_info = item.split(':')
        opt = tk.Checkbutton(option_frame, text=opt_info[0], variable=option_var, offvalue=0, onvalue=opt_info[1])
        opt.pack(side = tk.LEFT)

AddSingleChoiceQuestion(top, '问题1: 1 + 1 = ?', '1:2:3:4', q1_option)
AddSingleChoiceQuestion(top, '问题2: 10 - 10 = ?', '10:9:8:7', q2_option)
AddMultipleChoiceQuestion(top, '问题3: 100 * 100 = ?', '1:31|9:32|1:33|2:34', q3_option)
AddMultipleChoiceQuestion(top, '问题4: 1000 / 1000 = ?', '100:41|90:42|80:43|70:44', q4_option)

def OnSubmit():
    print(q1_option.get(), q2_option.get(), q3_option.get(), q4_option.get())

submit_btn =  tk.Button(top, width=8, text='交卷', command=OnSubmit)
submit_btn.pack()

top.mainloop()